package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.annotation.Login;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.user.service.UserListenProcessService;
import com.atguigu.tingshu.vo.user.UserListenProcessListVo;
import com.atguigu.tingshu.vo.user.UserListenProcessVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Map;

@Tag(name = "用户声音播放进度管理接口")
@RestController
@RequestMapping("api/user/userListenProcess")
@SuppressWarnings({"unchecked", "rawtypes"})
public class UserListenProcessApiController {
    @Autowired
    private UserListenProcessService userListenProcessService;

    @GetMapping("findUserPage/{page}/{limit}")
    @Operation(summary = "分页查询历史记录")
    @Login
    public Result<Page<UserListenProcessListVo>> findUserPage(@PathVariable Integer page, @PathVariable Integer limit) {
        Page<UserListenProcessListVo> userListenProcessPage = userListenProcessService.findUserPage(page, limit);
        return Result.ok(userListenProcessPage);
    }

    @Login(required = false)
    @Operation(summary = "根据声音id查询声音播放进度")
    @GetMapping("getTrackBreakSecond/{trackId}")
    public Result<BigDecimal> getTrackBreakSecond(@PathVariable Long trackId) {
        BigDecimal breakSeconds = userListenProcessService.getTrackBreakSecond(trackId);
        return Result.ok(breakSeconds);
    }

    @Login(required = false)
    @Operation(summary = "更新声音播放进度")
    @PostMapping("updateListenProcess")
    public Result updateListenProcess(@RequestBody UserListenProcessVo userListenProcessVo) {
        userListenProcessService.updateListenProcess(userListenProcessVo);
        return Result.ok();
    }

    @GetMapping("getLatelyTrack")
    @Login(required = false)
    public Result<Map<String,Long>> getLatelyTrack() {
        Map<String,Long> map = userListenProcessService.getLatelyTrack();
        return Result.ok(map);
    }
}

